home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / rspfdump.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  4KB  |  185 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "socket.h"
  7. #include "ip.h"
  8. #include "rspf.h"
  9. #ifdef UNIX
  10. #include "trace.h"
  11. #endif
  12.  
  13. /* Dump an RSPF packet */
  14. void
  15. #ifdef MONITOR
  16. rspf_dump(fp,bpp,source,dest,check,mon)
  17. #else
  18. rspf_dump(fp,bpp,source,dest,check)
  19. #endif
  20. FILE *fp;
  21. struct mbuf **bpp;
  22. int32 source,dest;
  23. int check;        /* If 0, bypass checksum verify */
  24. #ifdef MONITOR
  25. int mon;
  26. #endif
  27. {
  28.     union rspf rspf;
  29.     struct pseudo_header ph;
  30.     int16 csum;
  31.     int sync;
  32.  
  33.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  34.         return;
  35.  
  36. #ifdef MONITOR
  37.     if (mon)
  38.         fprintf(fp, "RSPF ");
  39.     else
  40. #endif
  41.     fprintf(fp,"RSPF: ");
  42.  
  43.     /* Compute checksum */
  44.     ph.source = source;
  45.     ph.dest = dest;
  46.     ph.protocol = RSPF_PTCL;
  47.     ph.length = len_p(*bpp);
  48.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  49.         check = 0;    /* No checksum error */
  50.  
  51.     ntohrspf(&rspf,bpp);
  52.  
  53. #ifdef MONITOR
  54.     if (!mon)
  55. #endif
  56.     if(rspf.hdr.version != RSPF_VERSION)
  57.         fprintf(fp,"version %u ",rspf.hdr.version);
  58.     switch(rspf.hdr.type){
  59.     case RSPF_FULLPKT:
  60.         if(rspf.pkthdr.csum == 0)
  61.         check = 0;
  62. #ifdef MONITOR
  63.         if (mon)
  64.             fprintf(fp, "updt ");
  65.         else
  66.         {
  67. #endif
  68.         fprintf(fp,"type ROUTING UPDATE ");
  69.         if(rspf.pkthdr.fragtot != 1)
  70.         fprintf(fp,"fragment %u frag total %u ",rspf.pkthdr.fragn,
  71.                rspf.pkthdr.fragtot);
  72.         if(rspf.pkthdr.sync != 4)
  73.         fprintf(fp,"sync %u ",rspf.pkthdr.sync);
  74.         fprintf(fp,"nodes %u id %u",rspf.pkthdr.nodes,rspf.pkthdr.envid);
  75.         if(check)
  76.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  77. #ifdef MONITOR
  78.         }
  79. #endif
  80.         fprintf(fp,"\n");
  81.         if(rspf.pkthdr.sync != 0)
  82.         sync = rspf.pkthdr.sync - 4;
  83.         else
  84.         sync = len_p(*bpp);
  85.         if(sync % 5 != 0){
  86. #ifdef MONITOR
  87.         if (!mon)
  88. #endif
  89.         fprintf(fp,"      %d bytes\n",sync);
  90.         pullup(bpp,NULLCHAR,sync);
  91.         sync = 0;
  92.         }
  93.         rspfnodedump(fp,bpp,sync / 5,mon);
  94.         break;
  95.     case RSPF_RRH:
  96.         if(rspf.rrh.csum == 0)
  97.         check = 0;
  98. #ifdef MONITOR
  99.         if (mon)
  100.             fprintf(fp, "rrh");
  101.         else
  102.         {
  103. #endif
  104.         fprintf(fp,"type RRH seq 0x%04x flags %d",rspf.rrh.seq,rspf.rrh.flags);
  105.         if(check)
  106.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  107. #ifdef MONITOR
  108.         }
  109. #endif
  110.         fprintf(fp,"\n");
  111.         break;
  112.     default:
  113.         fprintf(fp,"Unknown packet type\n");
  114.     }
  115. }
  116.  
  117. void
  118. #ifdef MONITOR
  119. rspfnodedump(fp,bpp,adjcnt,mon)
  120. #else
  121. rspfnodedump(fp,bpp,adjcnt)
  122. #endif
  123. FILE *fp;        /* uses tputs() if NULLFILE */
  124. struct mbuf **bpp;    /* routing update without packet header */
  125. int adjcnt;        /* number of links before first node header */
  126. #ifdef MONITOR
  127. int mon;
  128. #endif
  129. {
  130.      int c, links = 0;
  131.      char buf[128];
  132.      struct rspfnodeh nodeh;
  133.      struct rspflinkh linkh;
  134.      *buf = '\0';
  135.      for(;;) {
  136.       if(*buf != '\0') {
  137.            if(fp != NULLFILE)
  138.             fprintf(fp,"%s",buf);
  139.            else
  140.             tputs(buf);
  141.            *buf = '\0';
  142.       }
  143.       if(len_p(*bpp) == 0)
  144.            break;
  145.       if(adjcnt){
  146.            if((c = PULLCHAR(bpp)) == -1)
  147.             break;
  148. #ifdef MONITOR
  149.            if (mon /*&& fp != NULLFILE*/)
  150.                sprintf(buf, "%s/%u ", inet_ntoa(pull32(bpp)), c);
  151.            else
  152. #endif
  153.            sprintf(buf,"            %s/%u\n",inet_ntoa(pull32(bpp)),c);
  154.            adjcnt--;
  155.            continue;
  156.       }
  157.       if(links){
  158.            if(ntohrspflink(&linkh,bpp) == -1)
  159.             break;
  160. #ifdef MONITOR
  161.            if (mon /*&& fp != NULLFILE*/)
  162.                sprintf(buf, "\n");
  163.            else
  164. #endif
  165.            sprintf(buf,"      horizon %u ERP factor %u cost %u adjacencies %u\n",
  166.                linkh.horizon,linkh.erp,linkh.cost,linkh.adjn);
  167.            adjcnt = linkh.adjn;
  168.            links--;
  169.            continue;
  170.       }
  171.       if(ntohrspfnode(&nodeh,bpp) == -1)
  172.            break;
  173. #ifdef MONITOR
  174.       if (mon /*&& fp != NULLFILE*/)
  175.           sprintf(buf, "%s\n", inet_ntoa(nodeh.addr));
  176.       else
  177. #endif
  178.       sprintf(buf,"      Reporting Router: %s Seq %u Subseq %u links %u\n",
  179.           inet_ntoa(nodeh.addr),(int16)nodeh.seq,nodeh.subseq,
  180.           nodeh.links);
  181.       links = nodeh.links;
  182.      }
  183. }
  184.  
  185.